void main() {
  List nums = <int>[1, 2, 3];

  // for 循环
  for (var i = 0; i < nums.length; i++) {
    print(nums[i]);
  }

  for (var item in nums) {
    print(item);
  }

  nums.forEach((element) {
    print(element);
  });

  var newNums = nums.map((e) {
    return e * e;
  }).toList();
  print(newNums);

  bool isOdd(n) => n % 2 == 1;
  List oddNum = nums.where((el) => isOdd(el)).toList();
  print(oddNum);

  // any 是否有至少一个
  print(nums.any(isOdd));
  // every 全部都满足
  print(nums.every(isOdd));

  // 扩展
  List pairs = [
    [1, 2],
    [3, 4]
  ];
  List flattened = pairs.expand((el) => el).toList();
  print(flattened);

  // 折叠
  num result = nums.fold(2, (p, ele) => p * ele);
  print(result);
}
